﻿using System;
using Common;
using Jason.Handlers.Commands;
using Jason.Model;
using Microsoft.ServiceBus;
using Microsoft.ServiceBus.Messaging;

namespace Command.Core
{
    public class TestCommand : AbstractDataObject
    {
        public String Value { get; set; }
    }

    public class TestResponse : AbstractDataObject
    {
        public Boolean Result { get; set; }
    }

    public class TestCommandHandler : AbstractCommandHandler<TestCommand>
    {
        protected override Object OnExecute(TestCommand command)
        {
            ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http;

            var manager = NamespaceManager.Create();
            if (!manager.QueueExists("queue"))
                manager.CreateQueue("queue");

            var client = QueueClient.Create("queue");
            var message = new BrokeredMessage(new Message());
            client.Send(message);

            return new TestResponse {Result = command.Value.Length > 5};
        }
    }
}